﻿using System;

namespace Development.DbData
{
    public class DbDataAttribute : Attribute
    {
        public DbDataAttribute()
        {
            DefaultValue();
        }

        public DbDataAttribute(string dbName,bool isRank = false)
        {
            DefaultValue();
            DbName = dbName;
            IsRank = isRank;
        }
        public DbDataAttribute(bool iskey)
        {
            DefaultValue();
            this.IsKey = iskey;
            this.Isnullable = false;
        }

        public DbDataAttribute(bool iskey,int lenth,bool isIdentity)
        {
            DefaultValue();
            this.IsKey = iskey;
            this.IsIdentity = IsIdentity;
            this.Length = lenth;
        }

        public DbDataAttribute(int lenth,int scale)
        {
            DefaultValue();
            this.Length = lenth;
            this.Scale = scale;
        }

        public DbDataAttribute(int lenth)
        {
            DefaultValue();
            this.Length = lenth;
        }

        void DefaultValue()
        {
            IsKey = false;
            Length = 11;
            Scale = 0;
            Isnullable = true;
            IsIdentity = false;
        }

        public string DbName { get; set; }
        /// 是否是主键
        /// </summary>
        public bool IsKey { get; set; }
        /// <summary>
        /// 长度
        /// </summary>
        public long Length { get; set; }
        /// <summary>
        /// decimal类型指精度范围
        /// </summary>
        public int Scale { get; set; }
        /// <summary>
        /// 是否可为空
        /// </summary>
        public bool Isnullable { get; set; }

        /// <summary>
        /// 是否是自增列
        /// </summary>
        /// <value><c>true</c> if this instance is identity; otherwise, <c>false</c>.</value>
        public bool IsIdentity { get; set; }

        /// <summary>
        /// 是否为排序
        /// </summary>
        public bool IsRank { get; set; }
    }
}
